d1 <- simulated_scatter %>%
filter (group == 24 ) %>%
mutate (outlier = if_else (y == min (y), TRUE , FALSE ))
d2 <- simulated_scatter %>%
filter (group == 25 ) %>%
mutate (outlier = if_else (y == min (y), TRUE , FALSE ))
d3 <- simulated_scatter %>%
filter (group == 26 ) %>%
mutate (outlier = if_else (y == max (y), TRUE , FALSE ))
m1_aug <- augment (lm (y ~ x, data = d1)) %>%
mutate (outlier = if_else (y == min (y), TRUE , FALSE ))
m2_aug <- augment (lm (y ~ x, data = d2)) %>%
mutate (outlier = if_else (y == min (y), TRUE , FALSE ))
m3_aug <- augment (lm (y ~ x, data = d3)) %>%
mutate (outlier = if_else (y == max (y), TRUE , FALSE ))
p_1 <- ggplot (d1, aes (x = x, y = y)) +
geom_point (size = 2 , alpha = 0.8 ) +
geom_smooth (method = "lm" , se = FALSE ) +
geom_point (data = d1 %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["red" , "full" ], stroke = 2 ) +
labs (title = "A" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (expand = expansion (mult = 0.12 ))
p_1_res <- ggplot (m1_aug, aes (x = .fitted, y = .resid)) +
geom_point (alpha = 0.7 , size = 2 ) +
geom_hline (yintercept = 0 , linetype = "dashed" ) +
geom_point (data = m1_aug %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["red" , "full" ], stroke = 2 ) +
labs (x = "Predicted y" , y = "Residual" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (limits = c (- 8 , 8 ), expand = expansion (mult = 0.12 ))
p_2 <- ggplot (d2, aes (x = x, y = y)) +
geom_point (size = 2 , alpha = 0.8 ) +
geom_smooth (method = "lm" , se = FALSE ) +
geom_point (data = d2 %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["green" , "full" ], stroke = 2 ) +
labs (title = "B" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (expand = expansion (mult = 0.12 ))
p_2_res <- ggplot (m2_aug, aes (x = .fitted, y = .resid)) +
geom_point (size = 2 , alpha = 0.8 ) +
geom_hline (yintercept = 0 , linetype = "dashed" ) +
geom_point (data = m2_aug %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["green" , "full" ], stroke = 2 ) +
labs (x = "Predicted y" , y = "Residual" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (limits = c (- 8 , 8 ), expand = expansion (mult = 0.12 ))
p_3 <- ggplot (d3, aes (x = x, y = y)) +
geom_point (size = 2 , alpha = 0.8 ) +
geom_smooth (method = "lm" , se = FALSE ) +
geom_point (data = d3 %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["pink" , "full" ], stroke = 2 ) +
labs (title = "C" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (expand = expansion (mult = 0.12 ))
p_3_res <- ggplot (m3_aug, aes (x = .fitted, y = .resid)) +
geom_point (size = 2 , alpha = 0.8 ) +
geom_hline (yintercept = 0 , linetype = "dashed" ) +
geom_point (data = m3_aug %>% filter (outlier),
size = 5 , shape = "circle open" ,
color = IMSCOL["pink" , "full" ], stroke = 2 ) +
labs (x = "Predicted y" , y = "Residual" ) +
theme (
panel.grid = element_blank (),
axis.text = element_blank (),
panel.border = element_rect (colour = "gray" , fill = NA , size = 1 )
) +
scale_x_continuous (expand = expansion (mult = 0.12 )) +
scale_y_continuous (limits = c (- 8 , 8 ), expand = expansion (mult = 0.12 ))
p_1 + theme (plot.margin = unit (c (0 , 10 , 5 , 0 ), "pt" )) +
p_2 + theme (plot.margin = unit (c (0 , 10 , 5 , 0 ), "pt" )) + p_3 +
p_1_res + theme (plot.margin = unit (c (0 , 10 , 5 , 0 ), "pt" )) +
p_2_res + theme (plot.margin = unit (c (0 , 10 , 5 , 0 ), "pt" )) + p_3_res +
plot_layout (ncol = 3 , heights = c (2 , 1 ))